<?php

	header("Cache-Control: no-cache, must-revalidate");

	session_start();

	require_once ("model/User.php");
	require_once ("model/Session.php");
	require_once ("view/HTMLPageView.php");
	
	if (isset($_SESSION["thisSession"]))
	{	
		$session = new \model\Session();
		$session->validateSession($session);
	}
	if (isset($_COOKIE["Name"]) && isset($_COOKIE["Password"]))
	{
		$session = new \model\Session();
		$session->validateSession($session);
	}
	else if (isset($_POST["Name"]) && isset($_POST["Password"]))
	{
		$user = new \model\User($_POST["Name"], $_POST["Password"]);
		$user->validateUser($user);
	}		
	else if	(!isset($_SESSION["thisSession"]))
	{
		header("Location: labb2.php");
	}
	else	
	{
		$pageView = new \view\HTMLPageView();
		echo $pageView->getPage("Logga in", "Ej Inloggad", $returningName);
	}